package com.yamaikj.service.impl;


//import com.codingapi.txlcn.tc.annotation.DTXPropagation;
//import com.codingapi.txlcn.tc.annotation.LcnTransaction;
//import com.codingapi.txlcn.tc.annotation.TxcTransaction;
import com.yamaikj.config.DataSource;
import com.yamaikj.config.DataSourceType;
import com.yamaikj.dao.UserDao;
import com.yamaikj.feign.GoodsServiceFeign;
import com.yamaikj.model.User;
import com.yamaikj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Autowired
    GoodsServiceFeign goodsServiceFeign;

    @Override
    @DataSource(DataSourceType.SLAVE)
    public User findUserById(Long id) {
        return userDao.findUserById(id);
    }

//    @LcnTransaction //分布式事务注解
//    @Transactional //本地事务注解
    @DataSource(DataSourceType.MASTER)
    public User save(User user) {
        User users = userDao.save(user);
        //goodsServiceFeign.save();
//        int i = 1 / 0;
        return users;
    }

    @Override
    @DataSource(DataSourceType.MASTER)
    public User findUserByIdForUpdate(Long id) {
        return userDao.findUserById(id);
    }

}
